package Operation;

import Book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:岁亮亮
 * Date:2024-01-14
 * TIME:15:25
 */
public class modify implements Iooperation{
    public static void menu(){
        System.out.println("************************");
        System.out.println(" 请输入你要修改的那个地方");
        System.out.println(" 0  退出修改");
        System.out.println(" 1  修改书名");
        System.out.println(" 2  修改作者");
        System.out.println(" 3  修改类型");
        System.out.println(" 4  修改价格");
        System.out.println("************************");
    }
    @Override
    public void work(BookList bookList) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("修改图书");
        System.out.println("请输入你要修改图书的书名");
        String name=scanner.nextLine();
        int flag=-1;
        for (int i = 0; i < bookList.getUsesize(); i++) {
            if(name.equals(bookList.getbooks(i).getName() )){
                flag=1;
                menu();
                while (true){
                    System.out.println("请输入你要修改的内容序号");
                    int choice=scanner.nextInt();
                    if(choice==1){
                        System.out.println("请输入你要修改图书的书名");
                        Scanner scanner1=new Scanner(System.in);
                        String str=scanner1.nextLine();
                        for (int j = 0; j < bookList.getUsesize(); j++) {
                            if(str.equals(bookList.getbooks(j).getName())){
                                System.out.println("已有相同书名的图书 修改失败");
                                break;
                            }
                            else {
                                bookList.getbooks(i) .setName(str) ;
                                System.out.println(bookList.getbooks(i) );
                                System.out.println("修改图书书名成功");
                                break;
                            }
                        }

                    }
                    else if(choice==2){
                        System.out.println("请输入你要修改图书的作者名字");
                        Scanner scanner2=new Scanner(System.in);
                        String str=scanner2.nextLine();
                        bookList.getbooks(i) .setAuthor(str); ;
                        System.out.println(bookList.getbooks(i) );
                        System.out.println("修改图书作者成功");
                    }
                    else if(choice==3){
                        System.out.println("请输入你要修改图书的类型");
                        Scanner scanner3=new Scanner(System.in);
                        String str=scanner3.nextLine();
                        bookList.getbooks(i) .setType(str); ;
                        System.out.println(bookList.getbooks(i) );
                        System.out.println("修改图书类型成功");
                    }
                    else if(choice==4) {
                        System.out.println("请输入你要修改图书的书名");
                        Scanner scanner4 = new Scanner(System.in);
                        int str = scanner4.nextInt();
                        bookList.getbooks(i).setPrice(str);
                        System.out.println(bookList.getbooks(i));
                        System.out.println("修改图书价格成功");
                    }
                    else if(choice==0){
                        break;
                    }
                    else {
                        System.out.println("选择错误  请重新选择序号");
                    }
                }
            }
        }
        if(flag==-1){
            System.out.println("书架上没有找到你要修改的图书");
        }

    }
}
